package com.cty._01_Base._02_Singleton;

/**
 * @Auther: cty
 * @Date: 2020/6/25 9:11
 * @Description: 双重检查锁实现单例模式
 * @version: 1.0
 */
public class Singleton05 {
    private static Singleton05 instance;

    private Singleton05(){
    }

    public static Singleton05 getInstance(){
        if(instance == null){  // if 1
            Singleton05 s;
            synchronized(Singleton05.class){  // syn 1
                s = instance;
                if(s == null){  // if 2
                    synchronized(Singleton05.class){  // syn2
                        if(s == null)
                            s = new Singleton05();
                    }  // end syn 2
                    instance = s;
                }  // end if 2
            }  // end syn 1
        }  // end if 1
        return instance;
    }  // end getInstance{}

}  // end Singleton05{}
